<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/1
 * Time: 15:13
 * 金币兑换商品
 */
namespace app\admin\controller;
use think\Db;
class Convert  extends Base{
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_convert')->alias('a')

                ->count();//计算总页面
            $list = Db::table('up_convert')
                ->alias ('a')
                ->page($page, $limit)
                ->select();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
    }

    public function update(){
        if(request()->isPost ()){
            extract(input());
            $id = input('param.id');
            $param = [
                'convert_num'=>input('param.value'),
            ];
            $res = Db::name('convert')->where('convert_id',$id)->update($param);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        return $this->fetch();
    }
}
